$(function(){
	//出发地
	var list = [
		{name:'恩施州',zrr:0,zwry:0,fr:0},
		{name:'十堰市',zrr:0,zwry:0,fr:0},
		{name:'宜昌市',zrr:0,zwry:0,fr:0},
		{name:'襄阳市',zrr:0,zwry:0,fr:0},
		{name:'黄冈市',zrr:0,zwry:0,fr:0},
		{name:'荆州市',zrr:0,zwry:0,fr:0},
		{name:'荆门市',zrr:0,zwry:0,fr:0},
		{name:'咸宁市',zrr:0,zwry:0,fr:0},
		{name:'随州市',zrr:0,zwry:0,fr:0},
		{name:'孝感市',zrr:0,zwry:0,fr:0},
		{name:'武汉市',zrr:0,zwry:0,fr:0},
		{name:'黄石市',zrr:0,zwry:0,fr:0},
		{name:'神农架林区',zrr:0,zwry:0,fr:0},
		{name:'天门市',zrr:0,zwry:0,fr:0},
		{name:'仙桃市',zrr:0,zwry:0,fr:0},
		{name:'潜江市',zrr:0,zwry:0,fr:0},
		{name:'鄂州市',zrr:0,zwry:0,fr:0}       
	];
	getRegBarData();
	getCityBarData();
	getProvinceData();
	showMap();
	//获取市州注册总量数据
	function getRegBarData(){
		var res={"message":"调用成功!","shang":[""],"name":["用户总数","省内社会人员","省外社会人员","未实名社会人员","省内法人","省外法人","省直政务人员","市州政务人员"],"xia":["336388","196325","7199","24347","10003","52","4821","93641"],"success":true};
		var name = res.name;
		var shang = res.shang;
		var xia = res.xia;
		bar1(name,shang,xia); 
	}
	//获取市州注册数据
	function getCityBarData(){
		var res={"message":"调用成功!","data":{"name":["武汉市","襄阳市","宜昌市","十堰市","荆州市","荆门市","黄石市","鄂州市","孝感市","黄冈市","咸宁市","随州市","恩施州","仙桃市","潜江市","天门市","神农架林区"],"zrr":["12101","16154","86248","2938","13937","4126","1932","1914","9135","6668","4785","1393","15246","6929","2177","1552","206"],"fr":["814","389","4357","336","328","335","140","110","609","395","214","200","804","86","254","72","23"],"gwy":["13314","6127","5303","2756","3206","4008","2314","1520","15543","19560","2583","899","6719","5099","1316","3378","0"],"totalCount":290552,"zrrCount":187441,"gwyCount":93645,"frCount":9466},"success":true};
		var name = res.data.name;
		var zrr = res.data.zrr;
		var fr = res.data.fr;
		var gwy = res.data.gwy;
		var zrrCount = res.data.zrrCount;
		var gwyCount = res.data.gwyCount;
		var frCount = res.data.frCount;
		var totalCount = res.data.totalCount;
		bar2(name,zrr,fr,gwy,zrrCount,frCount,gwyCount);
		
		 //生成地图数据
		 var arr = new Array();
		 for(var index = 0; index < name.length; index++){
			 arr.push(eval("({name:'"+name[index]+"',zrr:"+zrr[index]+",zwry:"+gwy[index]+",fr:"+fr[index]+"})"));
		 }
		 list = arr; 
	}
	//获取省直柱状图数据
	function getProvinceData(){
		var res={"message":"调用成功!","feishidian":{"zrr":["1932","1914","9135","6668","4785","1393","15246","6929","2177","1552","206"],"name":["黄石市","鄂州市","孝感市","黄冈市","咸宁市","随州市","恩施州","仙桃市","潜江市","天门市","神农架林区"],"gwy":["2315","1520","15543","19560","2583","899","6719","5099","1316","3378","0"]},"shidian":{"zrr":["12101","16154","86248","2938","13937","4126"],"name":["武汉市","襄阳市","宜昌市","十堰市","荆州市","荆门市"],"gwy":["13315","6127","5303","2756","3206","4008"]},"hb":{"num":["188","1122","12","194","88","38","66","137","33","50","466","291","17","84","63","31","11","21","76","57","355","252","11","8","191","268","56","51","23","148","15","106","11","7","0","5","70","3","0","5","20","0","2","4","2","0","3","8","9","11","19","4","34","26","9","3","0","1","0","0","27","0","0","0","0","0","0","0","5","4"],"name":["发改委","编办","经信委","教育厅","科技厅","民宗委","公安厅","民政厅","司法厅","财政厅","人社厅","国土厅","环保厅","住建厅","交通厅","水利厅","农业厅","林业厅","商务厅","文化厅","卫计委","地税局","广电局","体育局","统计局","工商局","外侨办","质监局","旅游委","粮食局","物价局","安监局","产权局","公共资源","南水北调","测绘局","食药监","国防工办","政采中心","人防办","移民局","扶贫办","机关事务","审计厅","国资委","农垦局","地震局","方志办","供销社","气象局","畜牧局","档案局","水产局","残联","信访局","妇联会","研究室","法制办","生态保护站","保密局","农机局","密码管理局","种子管理局","征兵办","耕地肥料站","植保站","监狱局","老龄委","政府办公厅","省常委会"]},"success":true};

		 //省直名称
		 var provinceName = res.hb.name;
		 //省直数据
		 var provinceData = res.hb.num;
		 bar3(provinceName,provinceData); 
	}
	//柱状图
	function bar1(name,shang,xia){
		var line1 = echarts.init(document.getElementById("bar1"));
		option = {
			tooltip : {
				trigger: 'axis',
				axisPointer : {            // 坐标轴指示器，坐标轴触发有效
			    	 type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
			},
				formatter: function (params) {
					var tar = params[1];
					return tar.name + '<br/>' + tar.seriesName + ' : ' + tar.value;
				}
			},
			grid: {
				top : 80,
				left: '3%',
				right: '4%',
				bottom: 80,//'3%',
				containLabel: true
			},
			xAxis: {
				type : 'category',
			    splitLine: {show:false},
			    axisLabel: { interval: 0, rotate: 0, margin: 2, textStyle: { color: '#fff', fontSize: 15 } },
				data : name
			},
			yAxis: {
				type : 'value',
				splitLine: {show:false},
				axisLabel: {textStyle: { color: '#036192'} },
			},
			series: [
				{
			    	name: '缺省值',
			    	type: 'bar',
			    	stack:  '总量',
			    	itemStyle: {
			        	normal: {
			        		barBorderColor: 'rgba(0,0,0,0)',
			        		color: 'rgba(0,0,0,0)'
			        	},
			        	emphasis: {
			        		barBorderColor: 'rgba(0,0,0,0)',
			        		color: 'rgba(0,0,0,0)'
			        	}
			    	},
			    	data: [0,0,0,0,0,0,0,0]//shang
			    },
			    {
			    	name: '总人数',
			        type: 'bar',
			        stack: '总量',
			        label: {
			        	normal: {
			            	show: true,
			            	position: 'inside'
			        	}
			        },
			        itemStyle: {
		                normal: {
		                    barBorderColor: 'rgba(0,0,0,0)',
		                    color: '#6AB0B8'//'#00b0f0'
		                },
		                emphasis: {
		                    barBorderColor: 'rgba(0,0,0,0)',
		                    color: '#00b0f0'
		                }
		            },
			        data:xia
			    }
			]
		};
		line1.setOption(option);
	}
	function bar2(name,zrr,fr,gwy,zrrCount,frCount,gwyCount){
		var line2 = echarts.init(document.getElementById("bar2"));
		option = {
			baseOption: {
				timeline: {show:false},
				title: {
			    	//subtext: '数据来自国家统计局'
				},
				tooltip: {
		        },
		        legend: {
		            x: 'center',
		            data: ['自然人', '法人', '政务人员'],
		            selected: {
		                '自然人': true, '法人': true, '政务人员': true
		            },
		            textStyle:{//图例文字的样式
		                color:'#ccc',
		                fontSize:16
		            }
		        },
		        calculable : true,
		        grid: {
		            top: 80,
		            bottom: 100,
		            tooltip: {
		                trigger: 'axis',
		                axisPointer: {
		                    type: 'shadow',
		                    label: {
		                        show: true,
		                        formatter: function (params) {
		                            return params.value.replace('\n', '');
		                        }
		                    }
		                }
		            }
		        },
		        xAxis: [
		            {
		                'type':'category',
		                //'axisLabel':{'interval':0},
		                'data':name,
		                axisLabel: { interval: 0, rotate: 45, margin: 2, textStyle: { color: '#fff', fontSize: 15 } },
		                splitLine: {show: false}
		            }
		        ],
		        yAxis: [
		            {
		                type: 'value',
		                name: '人数',
		                axisLabel: { 
		    				show: true, 
		    				textStyle: { 
		    					color: '#036192'
		    				} 
		    			},
		    			splitLine: {           // 分隔线
		    				show: true,
		    				lineStyle: {
		    					color: ['#052f54'],
		    					width: 1,
		    					type: 'solid'
		    				}
		    			}
		            }
		        ],
		        series: [
		            {name: '自然人', type: 'bar'},
		            {name: '法人', type: 'bar'},
		            {name: '政务人员', type: 'bar'},
		            {
		                name: '人数占比',
		                type: 'pie',
		                center: ['75%', '35%'],
		                radius: '28%',
		                z: 100
		            }
		        ]
			},
			options: [
				{
		            title: {text: ''},
		            series: [
		                {data: zrr},
		                {data: fr,itemStyle: {color: '#CA8622'}},
		                {data: gwy,itemStyle: {color: '#6AB0B8'}},
		                {data: [
		                    {name: '自然人', value:zrrCount },//dataMap.dataPI['2002sum']
		                    {name: '法人', value: frCount,itemStyle: {color: '#CA8622'}},//dataMap.dataSI['2002sum']
		                    {name: '政务人员', value: gwyCount,itemStyle: {color: '#6AB0B8'}}//dataMap.dataTI['2002sum']
		                ]}
		            ]
		        }
			]
		}
		line2.setOption(option);
	}
	function bar3(name,data){
		var line3 = echarts.init(document.getElementById("bar3"));
		var option = {
			tooltip : {
				trigger: 'axis'
			},
			//legend: legend,
			grid : {top :30,bottom:55,left : 90,right: 50},
			calculable : true,
			xAxis :  [{type : 'category', axisLabel: { interval: 0, rotate: 35, margin: 2, textStyle: { color: '#fff', fontSize: 15 } },
						 data : name}],
			yAxis :{ 
				type: 'value', 
				axisLabel: { 
					show: true, 
					textStyle: { 
						color: '#036192'
						//fontSize: 18 
					} 
				} ,
				splitLine: {           // 分隔线
					show: true,
					lineStyle: {
						color: ['#052f54'],
						width: 1,
						type: 'solid'
					}
				}
			},
			series : [
				{name:'',type:'bar',data:data,itemStyle:{normal:{label : {show: true, position: 'top',textStyle: {color: '#ffff00'}},color:'#8FBC8F'}}}]
			};
		line3.setOption(option);
	}
	
	var geoCoordMap = {
			'恩施州':[109.5007,30.2563],		
			'十堰市':[110.5115,32.3877],		
			'宜昌市':[111.1707,30.7617],		
			'襄阳市':[111.9397,31.9263],		
			'黄冈市':[115.2686,30.6628],		
			'荆州市':[113.291,30.0092],		
			'荆门市':[112.6758,30.9979],		
			'咸宁市':[114.2578,29.6631],		
			'随州市':[113.4338,31.8768],		
			'孝感市':[113.9502,31.1188],		
			'武汉市':[114.3896,30.6628],		
			'黄石市':[115.0159,29.9213],		
			'神农架林区':[110.4565,31.5802],		
			'天门市':[113.0273,30.6409],		
			'仙桃市':[113.3789,30.3003],		
			'潜江市':[112.7637,30.3607],		
			'鄂州市':[114.7302,30.4102]	
	};
	function showMap(){
		 var map = echarts.init(document.getElementById("map"));
		 $.get('../../js/screen/hubei.json', function (geoJson) {
			 echarts.registerMap('HB', geoJson);
			 map.setOption(option = { 
				//backgroundColor: '#031528',
				 tooltip : {
			         trigger: 'item',
			         enterable:true,
			         formatter: function(params) {
			             var normal = '';
			             var name = params.data.fromName;
			             for(var i = 0;i < list.length; i++){
			            	 if(name == list[i].name){
			            		 normal = '<div class="toop-line title"><a>'+name+'</a><br/><a>法人：'+list[i].fr+'</a><br/><a>自然人：'+list[i].zrr+'</a><br/><a>政务人员：'+list[i].zwry+'</a></div>'
			            	 }
			             }
			             return normal;
			         }
			     },
			     geo: {
			    	 center:[112.17185,31.731877],
			    	 aspectScale:1,
			         map: 'HB',
			         zoom:1.2,
			         top : -10,
			         label: {
			             emphasis: {
			                 show: false
			             }
			         },
			         roam: false,
			         itemStyle: {
			             normal: {
			                 areaColor: '#194360',
			                 borderColor: '#f1f1f1'
			             },
			             emphasis: {
			                 areaColor: '#194360'
			             }
			         }
			     },
			     series: series
		        });
		 })
	 }
	function convertData(data) {
		    var res = [];
		    res = data.map(function (dataItem) {
		            var res = {};
		            var fromCoord = geoCoordMap[dataItem.name];
		            var toCoord = geoCoordMap['武汉市'];
		            var b = fromCoord && toCoord;
		            if (fromCoord && toCoord) {
		                return {
		                    fromName: dataItem.name,
		                    toName: '武汉市',
		                    coords: [fromCoord, toCoord]
		                };
		            }
		            return res;
		        })
		    return res;
	 };

	 var series = [];
	     series.push(
	         {
	             //name: keyname[i],
	             type: 'lines',
	             zlevel: 2,
	             effect: {
	                 show: true,
	                 period: 6,
	                 constantSpeed: 100,
	                 trailLength: 0.4,
	                 color: '#fff',
	                 symbolSize: 5
	             },
	             lineStyle: {
	                 normal: {
	                     color: '#f6d23b',
	                     width: 0,
	                     curveness: 0.2
	                 }
	             },
	             data: convertData(list) 
	         },
	         {
	             //name: keyname[i],
	             type: 'lines',
	             zlevel: 1,
	             effect: {
	                 show: true,
	                 period: 6,
	                 trailLength: 0,
	                 symbol: 'image://',
	                 symbolSize: 15
	             },
	             label: {
	                 emphasis: {
	                     show: true,
	                     
	                 }
	             },
	             lineStyle: {
	                 normal: {
	                     color: '#f6d23b',
	                     width: 2,
	                     opacity: 0.8,
	                     curveness: 0.2
	                 },
	                 emphasis:{
	                     color: '#f6d23b',
	                     shadowColor: 'rgba(0, 0, 0, 0.5)',
	                     shadowBlur: 10,
	                     width: 6
	                 }
	             },
	             data: convertData(list)
	         },
	         {
	             //name: keyname[i],
	             type: 'effectScatter',
	             coordinateSystem: 'geo',
	             zlevel: 2,
	             rippleEffect: {
	                 period: 5,
	                 scale: 8,
	                 brushType: 'stroke'
	             },
	             label: {
	                 normal: {
	                     show: true,
	                     position: 'right',
	                     formatter: '{b}',
	                     color: '#09bdc7',
	                     fontSize: 15	 
	                 }
	             },
	             symbolSize:5,
	             itemStyle: {
	                 normal: {
	                     areaColor:'#fff',
	                     color: '#f6d23b'
	                 }
	             },
	             data: list.map(function (dataItem) {
	                 return {
	                     name :dataItem.name,
	                     value : geoCoordMap[dataItem.name]//.concat([dataItem[key[i]]])
	                 };
	             })
	         }
	);
})